package com.dhcc.sds.busi.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.dhcc.cdc.busi.dao.CdcEpisodeMapper;
import com.dhcc.cdc.busi.entity.CdcEpisodeEntity;
import com.dhcc.cdc.busi.service.ICdcEpisodeService;
import com.dhcc.cdc.sys.cache.config.CdcConfigCache;
import com.dhcc.cdc.sys.cache.config.ICdcConfigCache;
import com.dhcc.cdc.sys.entity.ConfigurationEntity;
import com.dhcc.cdc.sys.service.IConfigurationService;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.security.ShiroKit;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.core.modules.system.entity.User;
import com.dhcc.sdc.busi.entity.SdcBusiQcMrlistEntity;
import com.dhcc.sdc.busi.service.ISdcBusiQcMrlistService;
import com.dhcc.sdc.busi.service.ISdcBusiQcfitemExecResultService;
import com.dhcc.sds.base.entity.SdsQcentityEntity;
import com.dhcc.sds.base.entity.SdsQcentityRuleEntity;
import com.dhcc.sds.base.entity.SdsQcfitemDicEntity;
import com.dhcc.sds.base.entity.SdsQcformItemEntity;
import com.dhcc.sds.base.service.*;
import com.dhcc.sds.busi.dto.SdsQcFormItemDto;
import com.dhcc.sds.busi.entity.SdsQcfitemExecresultEntity;
import com.dhcc.sds.busi.entity.SdsQcincaseEntity;
import com.dhcc.sds.busi.entity.SdsQcincaseOperlogEntity;
import com.dhcc.sds.busi.service.ISdsQcFormShowService;
import com.dhcc.sds.busi.service.ISdsQcfitemExecresultService;
import com.dhcc.sds.busi.service.ISdsQcincaseDataService;
import com.dhcc.sds.busi.service.ISdsQcincaseService;
import com.dhcc.sds.util.DateUtil;
import com.dhcc.sds.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.script.ScriptException;
import java.io.UnsupportedEncodingException;
import java.util.*;

/**
 * @version 1.0 DHCC
 * @Description: 表单填报页面
 * @author:sunyingjie
 * @date:2021年05月20日09:58:22
 * @Copyright: (c) DHCC All rights reserved.
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdsqcformshow")
public class SdsQcFormShowController extends BaseController {

    private String PREFIX = "/backend/sds/sdsqcformshow/";

    @Autowired
    private ISdsQcFormShowService sdsQcFormShowService;
    @Autowired
    private ISdsQcincaseService sdsQcincaseService;
    @Autowired
    private ISdsQcentityService sdsQcentityService;
    @Autowired
    private ISdsQcfitemDicService sdsQcfitemDicService;
    @Autowired
    private ISdsQcfitemExecresultService sdsQcfitemExecresultService;
    @Autowired
    private ISdsQcformItemService sdsQcformItemService;
    @Autowired
    private ISdsQcentityRuleService sdsQcentityRuleService;
    @Autowired
    private IConfigurationService configurationService;
    @Autowired
    private ISdsCommonService sdsCommonService;
    @Autowired
    private ISdsQcincaseDataService sdsQcincaseDataService;
    @Autowired
    private ICdcEpisodeService cdcEpisodeService;
    @Autowired
    private CdcEpisodeMapper episodeMapper;
    @Autowired
    private ISdcBusiQcMrlistService sdcBusiQcMrlistService;
    @Autowired
    private ISdcBusiQcfitemExecResultService sdcBusiQcfitemExecResultService;

    /**
     * 跳转到表单填报页面
     */
    @RequestMapping("")
    public String index(@RequestParam Map<String, Object> params, Model model) {
        Long mrListId = Long.valueOf(params.get("mrListId").toString());
        String execUser = "unknown";
        if (CommonUtil.isNotEmpty(params.get("execUser"))) {
            execUser = java.net.URLDecoder.decode(params.get("execUser").toString());
        } else {
            User user = ShiroKit.getUser();
            if (user!=null) {
                execUser = user.getLoginName();
            }
        }
        String reUploadFlag = "";
        if (CommonUtil.isNotEmpty(params.get("reUploadFlag"))) {
            reUploadFlag = params.get("reUploadFlag").toString();
        }

        String checkPerm =  params.get("checkPerm").toString();
        String channel = "0";
        if (params.get("channel") != null) {
            channel =  params.get("channel").toString();
        }
//        String submitPerm =  params.get("submitPerm").toString();

        // 查询入组详细
        SdsQcincaseEntity mrEntity = sdsQcincaseService.selectById(mrListId);
        // 查询病种详细
        SdsQcentityEntity qcEntity = sdsQcentityService.selectById(mrEntity.getEntityId());
        // 单病种医生是否可以直接上报配置
        String formCheckType = CdcConfigCache.me().getValueByKey("SDS", "SDFormCheckType");
        // 病历浏览路径
        String EMRPagePath = CdcConfigCache.me().getValueByKey("SDS", "EMRPagePath");
        // 单病种上报表单是否显示病历溯源
        String isShowDataTrace = CdcConfigCache.me().getValueByKey("SDS", "SDIsShowSourceData","N");
        // 是否合并上报流程
        String isMergeReport = CdcConfigCache.me().getValueByKey("SDS", "SDIsMergeReport", "N");
        model.addAttribute("execUser", execUser);
        model.addAttribute("mrListId", mrListId);
        model.addAttribute("entityId", mrEntity.getEntityId());
        model.addAttribute("episodeId", mrEntity.getEpisodeId());
        model.addAttribute("formCheckType", formCheckType);
        model.addAttribute("checkPerm", checkPerm);
//        model.addAttribute("submitPerm", submitPerm);
        model.addAttribute("reUploadFlag", reUploadFlag);
        model.addAttribute("EMRPagePath", EMRPagePath);
        model.addAttribute("isShowSourceData", isShowDataTrace);
        model.addAttribute("isMergeReport", isMergeReport);
        model.addAttribute("channel", channel);
        return PREFIX + qcEntity.getAbbrev() + ".html";
    }

//    /**
//     * 跳转到预填报表单页面(废弃)
//     */
//    @RequestMapping("/{episodeXcode}")
//    public String index(@PathVariable String episodeXcode, Model model) {
//        Long episodeId = episodeMapper.selectIdByXcode(episodeXcode);
//        String execUser = "unknown";
//        User user = ShiroKit.getUser();
//        if (user!=null) {
//            execUser = user.getLoginName();
//        }
//        String reUploadFlag = "0";
//
//        String checkPerm =  "1";
//        // 查询入组详细
//        SdsQcincaseEntity mrEntity = sdsQcincaseService.selectEntityByEpisodeId(episodeId);
//        if (mrEntity == null){
//            mrEntity = new SdsQcincaseEntity();
//            SdcBusiQcMrlistEntity qcMrlistEntity = sdcBusiQcMrlistService.getByEpisodeId(episodeId);
//            mrEntity.setEntityId(qcMrlistEntity.getEntityId());
//            mrEntity.setEpisodeId(qcMrlistEntity.getEpisodeId());
//            mrEntity.setState("P");
//            mrEntity.setGroupStatus("SysRec");
//            mrEntity.setFillingStatus("NotFilled");
//            mrEntity.setReportStatus("NotUp");
//            sdsQcincaseService.insert(mrEntity);
//        }
//        // 查询病种详细
//        SdsQcentityEntity qcEntity = sdsQcentityService.selectById(mrEntity.getEntityId());
//        // 单病种医生是否可以直接上报配置
//        String formCheckType = CdcConfigCache.me().getValueByKey("SDS", "SDFormCheckType");
//        // 病历浏览路径
//        String EMRPagePath = CdcConfigCache.me().getValueByKey("SDS", "EMRPagePath");
//        model.addAttribute("execUser", execUser);
//        model.addAttribute("mrListId", mrEntity.getId());
//        model.addAttribute("entityId", mrEntity.getEntityId());
//        model.addAttribute("episodeId", mrEntity.getEpisodeId());
//        model.addAttribute("formCheckType", formCheckType);
//        model.addAttribute("checkPerm", checkPerm);
//        model.addAttribute("reUploadFlag", reUploadFlag);
//        model.addAttribute("EMRPagePath", EMRPagePath);
//        return PREFIX + qcEntity.getAbbrev() + ".html";
//    }


    /**
     * 跳转病种排除页面
     */
    @RequestMapping("/excludereason")
    public String excludeReason(@RequestParam Map<String, Object> params, Model model) {
        Long mrListId = Long.valueOf(params.get("mrListId").toString());
        Long entityId = Long.valueOf(params.get("entityId").toString());
        String execUser = "";
        if (CommonUtil.isNotEmpty(params.get("execUser"))) {
            execUser = java.net.URLDecoder.decode(params.get("execUser").toString());
        } else {
            User user = ShiroKit.getUser();
            execUser = user.getLoginName();
        }
        // 查询入组详细
        Map param = new HashMap();
        param.put("entityId", entityId);
        param.put("isActive", 1);
        param.put("ruleType", 2);
        param.put("showFlag", 1);
        List<SdsQcentityRuleEntity> ruleDicts = sdsQcentityRuleService.list(param);
        ruleDicts.forEach(ruleDict -> {
            String ruleDesc = ruleDict.getRuleDesc();
            
        });
        model.addAttribute("mrListId", mrListId);
        model.addAttribute("entityId", entityId);
        model.addAttribute("execUser", execUser);
        model.addAttribute("ruleDicts", ruleDicts);
        return PREFIX + "sdsexcludereason.html";
    }

    /**
     * 跳转病种填报提醒内容页面
     */
    @RequestMapping("/qcrule")
    public String qcrule(@RequestParam Map<String, Object> params, Model model) {
        Long entityId = Long.valueOf(params.get("entityId").toString());
        // 查询入组详细
        Map param = new HashMap();
        param.put("entityId", entityId);
        param.put("isActive", 1);
        List<SdsQcentityRuleEntity> ruleDicts = sdsQcentityRuleService.list(param);
        List<SdsQcentityRuleEntity> intheRules = new ArrayList<>();
        List<SdsQcentityRuleEntity> excludeRules = new ArrayList<>();
        for (SdsQcentityRuleEntity ruleDict : ruleDicts) {
            if (Objects.equals("1",ruleDict.getRuleType())) {
                intheRules.add(ruleDict);
            } else {
                excludeRules.add(ruleDict);
            }
        }
        model.addAttribute("entityId", entityId);
        model.addAttribute("intheRules", intheRules);
        model.addAttribute("excludeRules", excludeRules);
        return PREFIX + "sdsqcrule.html";
    }

    /**
     * 通过字典代码查询表单单个值域字典项描述
     */
    @RequestMapping("/itemDicDesc")
    @ResponseBody
    public Object getItemDicDesc(@RequestParam Map<String, Object> params){
        Wrapper<SdsQcfitemDicEntity> wrapper = new EntityWrapper<>();
        wrapper.eq("form_item_id", params.get("formItemId"));
        wrapper.eq("code", params.get("code"));
        return sdsQcfitemDicService.selectOne(wrapper);
    }

    /**
     * 查询表单值域字典
     */
    @RequestMapping("/itemDics/{formItemId}")
    @ResponseBody
    public Object findItemDics(@PathVariable Long formItemId){
        // 查询项目值域
        return sdsQcfitemDicService.listByItemId(formItemId);
    }

    /**
     * 查询项目结果值
     */
    /*@RequestMapping("/itemVal/{formItemId}/{mrListId}")
    @ResponseBody
    public Map<String, Object> getInitVal(@PathVariable Long formItemId, @PathVariable Long mrListId){
        Map resMap = new HashMap();
        // 查询项目信息
        SdsQcformItemEntity formItem = sdsQcformItemService.selectById(formItemId);
        // 查询项目结果值
        Wrapper<SdsQcfitemExecresultEntity> wrapper = new EntityWrapper<>();
        wrapper.eq("in_case_id", mrListId);
        wrapper.eq("form_item_id", formItemId);
        SdsQcfitemExecresultEntity itemExec = sdsQcfitemExecresultService.selectOne(wrapper);
        // 查询关联项目并计算显示属性
        Integer editPower = 0;
        try {
            editPower = sdsQcFormShowService.calcTriggerExp(mrListId, formItem);
        } catch (ScriptException e) {
            e.printStackTrace();
        }
        resMap.put("itemExec", itemExec);
        resMap.put("editPower", editPower);
        return resMap;
    }*/
    
    /**
     * 查询项目结果值
     */
    @RequestMapping("/getItemInfo/{mrListId}")
    @ResponseBody
    public Object getItemInfo(@PathVariable Long mrListId){
        List<SdsQcFormItemDto> itemList = new ArrayList<>();
        try {
            // 打开表单填报页面是否自动取值
            String initMrList = CdcConfigCache.me().getValueByKey("SDS", "SDInitMrList","N");
            // 单病种上报表单是否显示病历溯源
            String isShowDataTrace = CdcConfigCache.me().getValueByKey("SDS", "SDIsShowDataTrace","N");
            if ("Y".equals(initMrList)) {
                // 根据数据源配置自动取值
                sdsQcfitemExecresultService.execItemResult(mrListId);
            }
            // 获取跟项目结果
            itemList =  sdsQcFormShowService.getItemResult(mrListId);
            itemList.get(0).setIsShowDataTrace(isShowDataTrace);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return itemList;
    }

    /**
     * 查询表单项目源数据详情
     * @param params
     * @return
     */
    @RequestMapping("/getItemSourceDetail")
    @ResponseBody
    public Object getItemSourceDetail(@RequestParam Map<String, Object> params){
        return R.ok(sdsQcFormShowService.getItemSourceDetail(params));
    }

    /**
     * 查询表单填报状态
     */
    @RequestMapping("/mrState/{mrListId}")
    @ResponseBody
    public Object getCurrStat( @PathVariable Long mrListId){
        String statCode = "";
        // 查询表单填报状态
        SdsQcincaseEntity mrEntity = sdsQcincaseService.selectById(mrListId);
        if (CommonUtil.isNotEmpty(mrEntity)) {
            statCode = mrEntity.getState();
        }
        return statCode;
    }

    /**
     * 获取前置条件关联此项目的项目ID
     */
    @RequestMapping("/triggerLinkItem")
    @ResponseBody
    public Object getTriggerLinkItem(@RequestParam Map<String, Object> params){
        return sdsQcFormShowService.getTriggerLinkItem(params);
    }

    /**
     * 获取项目id相关的校验规则涉及到的项目id，以便前台取值返回进行计算
     */
    @RequestMapping("/ruleLinkItem")
    @ResponseBody
    public Object getRuleLinkItem(@RequestParam Map<String, Object> params){
        return sdsQcFormShowService.getRuleLinkItem(params);
    }

    /**
     * 进行项目校验并返回校验提示信息
     */
    @RequestMapping("/validMsg")
    @ResponseBody
    public Object getValidMsg(@RequestParam Map<String, Object> params){
        JSONArray msgArr = new JSONArray();
        try {
            msgArr =  sdsQcFormShowService.getValidMsg(params);
        } catch (ScriptException e) {
            e.printStackTrace();
        }
        return msgArr;
    }

    /**
     * 对关联项目进行判断并返回显隐信息
     */
    @RequestMapping("/linkItemMsg")
    @ResponseBody
    public Object getLinkItemMsg(@RequestParam Map<String, Object> params){
        JSONArray msgArr = new JSONArray();
        try {
            msgArr =  sdsQcFormShowService.getLinkItemMsg(params);
        } catch (ScriptException | UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return msgArr;
    }

    /**
     * 获取该项目有关的逻辑取值相关联的项目及其他项
     */
    @RequestMapping("/GetLogicLinkItem")
    @ResponseBody
    public Object getLogicLinkItem(@RequestParam Map<String, Object> params){
        JSONArray logicItemArr = sdsQcFormShowService.getLogicLinkItem(params);
        return logicItemArr;
    }

    /**
     * 获取该项目有关的逻辑取值相关联的项目及其他项
     */
    @RequestMapping("/GetLinkItemDefaultVal")
    @ResponseBody
    public Object getLinkItemDefaultVal(@RequestParam Map<String, Object> params){
        return sdsQcFormShowService.getLinkItemDefaultVal(params);
    }

    /**
     * 表单项目实时取值相关联的项目
     */
    @RequestMapping("/getRealTimeItem")
    @ResponseBody
    public Object getRealTimeItem(@RequestParam Map<String, Object> params){
        return sdsQcFormShowService.getRealTimeItem(params);
    }

    /**
     * 保存病种项目结果值
     */
    @RequestMapping(value = "/save")
    @ResponseBody
    public Object save(@RequestParam Map<String, Object> params) {
        Boolean result;
        // 获取当前登录人姓名(设置为公共属性)
        String execUser = params.get("execUser").toString();
        Long mrListId  = Long.valueOf(params.get("mrListId").toString());
        Long itemId = Long.valueOf(params.get("itemId").toString());
        String itemVal ="";
        if (CommonUtil.isNotEmpty(params.get("itemVal"))) {
            itemVal = params.get("itemVal").toString();
        }
        // 删除值中的特殊字符
        itemVal = StrUtil.clearSpecialChar(itemVal);
        Date execDate = new Date();
        Wrapper<SdsQcfitemExecresultEntity> wrapper = new EntityWrapper<>();
        wrapper.eq("in_case_id", mrListId).eq("form_item_id", itemId);
        SdsQcfitemExecresultEntity execEntity = sdsQcfitemExecresultService.selectOne(wrapper);
        if (CommonUtil.isEmpty(execEntity)) {
            execEntity = new SdsQcfitemExecresultEntity();
            execEntity.setInCaseId(mrListId); // 入组id
            execEntity.setformItemId(itemId); //项目id
            execEntity.setItemResult(itemVal); //项目结果值
            execEntity.setExecUser(execUser); // 执行人
            execEntity.setExecDate(execDate); // 执行日期
            execEntity.setExecTime(execDate); // 执行时间
            execEntity.setExecType("H");
            // 新增
            result = execEntity.insert();
            //更新表单填报率
            if (!CommonUtil.isEmpty(itemVal)){
                SdsQcformItemEntity formItem = sdsQcformItemService.selectById(itemId);
                SdsQcincaseEntity sdsQcincaseEntity = sdsQcincaseService.selectById(mrListId);
                if (result){
                    sdsQcincaseEntity.setECount(sdsQcincaseEntity.getECount()+1);
                    if (Objects.equals(1, formItem.getBtIsNeeded())){
                        sdsQcincaseEntity.setNCount(sdsQcincaseEntity.getNCount()-1);
                    }
                }
                sdsQcincaseService.updateById(sdsQcincaseEntity);
            }
        } else {
            execEntity.setItemResult(itemVal); //项目结果值
            execEntity.setExecUser(execUser); // 执行人
            execEntity.setExecDate(execDate); // 执行日期
            execEntity.setExecTime(execDate); // 执行时间
            // 更新
            result = execEntity.updateAllColumnById();
        }

        if (result) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    /**
     * 更新表单填报状态
     */
    @RequestMapping(value = "/changeMrStatus")
    @ResponseBody
    public Object changeMrStatus(@RequestParam Map<String, Object> params) {
        String execUser;
        if (CommonUtil.isNotEmpty(params.get("execUser"))) {
            execUser = params.get("execUser").toString();
        } else {
            // 获取当前登录用户的部门
            User user = ShiroKit.getUser();
            execUser = user.getLoginName();
        }
        Date execDate = new Date();
        // 更新填报状态
        Long mrListId  = Long.valueOf(params.get("mrListId").toString());
        SdsQcincaseEntity mrListEntity = sdsQcincaseService.selectById(mrListId);
        String stateCode  = params.get("status").toString();
        String operStartTime = "";
        String operEndTime = "";
        if (params.get("operStartTime")!=null){
            operStartTime = params.get("operStartTime").toString();
        }
        if (params.get("operEndTime")!=null){
            operEndTime = params.get("operEndTime").toString();
            execDate = DateUtil.parseTime(operEndTime);
        }
        switch (stateCode) {
            case "Save":
//                //预填报用(废弃)
//                if (mrListEntity.getState().equals("P")){
//                    stateCode = "P";
//                }
                break;
            case "Submit":
                // 更新填报状态字段
                mrListEntity.setFillingStatus(stateCode);
                break;
            case "Up":
                // 更新上报状态字段
                mrListEntity.setReportStatus(stateCode);
                break;
            case "Back":
                // 更新填报状态字段
                mrListEntity.setFillingStatus("Save");
            case "O":
                mrListEntity.setOutDate(execDate);
                mrListEntity.setOutTime(execDate);
            default:
                break;
        }
        // 查询单病种状态字典，更新当前状态字段
        mrListEntity.setState(stateCode);
        mrListEntity.setId(mrListId);
//        if (params.get("testFlg")!=null) {
//            mrListEntity.setTestFlg((Integer) params.get("testFlg"));
//        }
        sdsQcincaseService.updateById(mrListEntity);

        // -wl 医生直接上报成功自动审核留痕
        String isAutoCheck = CdcConfigCache.me().getValueByKey("SDS", "SDIsAutoCheck", "N");
        if (CommonUtil.equals(isAutoCheck, "Y")&&CommonUtil.equals(stateCode, "Up")) {
            SdsQcincaseOperlogEntity tmpLogEntity = new SdsQcincaseOperlogEntity();
            tmpLogEntity.setInCaseId(mrListId);
            tmpLogEntity.setOperState("Check");
            tmpLogEntity.setOperUser("系统");
            tmpLogEntity.setOperDate(execDate);
            tmpLogEntity.insert();
        }

        // 增加病例操作日志
        SdsQcincaseOperlogEntity sdsQcincaseOperlogEntity = new SdsQcincaseOperlogEntity();
        sdsQcincaseOperlogEntity.setInCaseId(mrListId);
        sdsQcincaseOperlogEntity.setOperState(stateCode);
        if (params.get("reason")!=null) {
            sdsQcincaseOperlogEntity.setOperReason(String.valueOf(params.get("reason")));
        }
        if (params.get("resume")!=null) {
            sdsQcincaseOperlogEntity.setOperResume(String.valueOf(params.get("resume")));
        }
        sdsQcincaseOperlogEntity.setOperUser(execUser);
        sdsQcincaseOperlogEntity.setOperDate(execDate);
        if (CommonUtil.isNotEmpty(operStartTime)){
            Date date = DateUtil.parseTime(operStartTime);
            sdsQcincaseOperlogEntity.setOperStartDate(date);
        }
        sdsQcincaseOperlogEntity.insert();

        //如果存在门户数据采集程序，更新维度数据
        sdsQcincaseDataService.updatePortalData(mrListId);

        //处理his消息  为空和为-1都是无消息时调用
        if(CommonUtil.isNotEmpty(params.get("msgDetailsId"))&&CommonUtil.isNotEmpty(params.get("execUserId"))){
            sdsQcFormShowService.handleHisMessage((String)params.get("msgDetailsId"),params.get("execUserId").toString());
        }
        return R.ok();
    }

    /**
     * 单病种上报
     */
    @RequestMapping(value = "/upload/{mrListId}")
    @ResponseBody
    public Object upload(@PathVariable Long mrListId) {
        Map<String, Object> map = new HashMap<>();
        try {
            // 获取表单数据
            List<SdsQcFormItemDto> formItemList = this.sdsQcFormShowService.getItemInfo(mrListId);
            // 组装接口数据
            JSONObject dataJSON = this.sdsQcFormShowService.assembData(formItemList);
            // 上传数据
            map = this.sdsQcFormShowService.uploadData(mrListId, dataJSON);
        } catch (Exception e) {
            e.printStackTrace();
            R.error(e.getMessage());
        }
        return R.ok(map);
    }

    /**
     * 表单项目取值
     */
    @RequestMapping(value = "/execItemValue/{mrListId}")
    @ResponseBody
    public void execItemResult(@PathVariable Long mrListId) {
        sdsQcfitemExecresultService.execItemResult(mrListId);
    }


    /**
     * @param params
     * @return
     * @Description: 跳转评估页面
     * @Title: showASMT
     * @author: sunyingjie
     * @date: 2021年09月16日15:08:52
     */
    @RequestMapping(value = "/showASMT")
    public String showASMT(@RequestParam Map<String, Object> params, Model model) {
        Long asmtId = Long.valueOf(params.get("asmtId").toString());
        Long mrListId = Long.valueOf(params.get("mrListId").toString());
        Long fitemId = Long.valueOf(params.get("itemId").toString());
        // 查询入组详细
        SdsQcincaseEntity mrEntity = sdsQcincaseService.selectById(mrListId);
        model.addAttribute("patientId", mrEntity.getEpisodeId());
        model.addAttribute("asmtId", asmtId);
        model.addAttribute("fitemId", fitemId);
        return PREFIX + "sdsasmt.html";
    }

    /**
     * @param params
     * @return
     * @Description: 获取评估量表信息
     * @Title: getAsmtInfo
     * @author: sunyingjie
     * @date: 2021年09月16日15:08:52
     */
    @RequestMapping(value = "/getAsmtInfo")
    @ResponseBody
    public Object getAsmtInfo(@RequestParam Map<String, Object> params){
        return this.sdsQcFormShowService.getAsmtInfo(params);
    }

    /**
     * @param params
     * @return
     * @Description: 保存评估结果
     * @Title: saveAsmtInfo
     * @author: sunyingjie
     * @date: 2021年09月16日15:08:52
     */
    @RequestMapping(value = "/saveAsmtInfo")
    @ResponseBody
    public Object saveAsmtInfo(@RequestParam Map<String, Object> params) {
        // 保存禁忌信息到相关项目结果表
        sdsQcFormShowService.saveAsmtInfo(params);
        return R.ok();
    }

    /**
     * @param params
     * @return
     * @Description: 上报自动评估保存至t_sdc_busi_evaluation_his
     * @Title: saveAIAsmtInfo
     * @author: ruimin
     */
    @RequestMapping(value = "/saveAIAsmtInfo")
    @ResponseBody
    public void saveAiNodeInfo(@RequestParam Map<String, Object> params) {
        sdsQcFormShowService.saveAIAsmtInfo(params);
    }
    /**
     * @param params
     * @return
     * @Description: 上报自动评估返回信息
     * @Title: getAIAsmtInfo
     * @author: ruimin
     */
    @RequestMapping(value = "/getAIAsmtInfo")
    @ResponseBody
    public Object getAIAsmtInfo(@RequestParam Map<String, Object> params) {
        return sdsQcFormShowService.getAIAsmtInfo(params);
    }

    /**
     * 跳转到病历溯源
     */
    @RequestMapping("/displaySumInfo")
    public String displaySumInfo(@RequestParam Map<String, Object> params, Model model) {
        Long mrListId = Long.valueOf(params.get("mrListId").toString());
        Long formItemId = Long.valueOf(params.get("formItemId").toString());
        //SdsQcformItemEntity sdsQcformItem = this.sdsQcformItemService.getInfoById(formItemId);
        SdsQcincaseEntity mrEntity = sdsQcincaseService.selectById(mrListId);
        CdcEpisodeEntity episodeEntity = cdcEpisodeService.selectById(mrEntity.getEpisodeId());
        String dateFormat = cn.hutool.core.date.DateUtil.format(episodeEntity.getAdmDate(), "yyyy-MM-dd HH:MM:SS");
        model.addAttribute("episodeName",episodeEntity.getName());
        model.addAttribute("episodeAge",episodeEntity.getAge());
        model.addAttribute("episodeGender",episodeEntity.getGender());
        model.addAttribute("episodeMrNum",episodeEntity.getMrNum());
        model.addAttribute("episodeAdmLocDesc",episodeEntity.getAdmLocDesc());
        model.addAttribute("episodeAdmDate",dateFormat);
        model.addAttribute("episodeId",episodeEntity.getId());
        model.addAttribute("mrListId",mrListId);
        model.addAttribute("formItemId",formItemId);
        return PREFIX + "sdsqcsuminfo.html";
    }

    /**
     * @param params
     * @return
     * @Description: 获取病历溯源就诊信息
     * @Title: getDataByAdm
     * @author: zhangdc
     * @date: 2023年12月7日15:08:52
     */
    @RequestMapping(value = "/getDataByAdm")
    @ResponseBody
    public Object getDataByAdm(@RequestParam Map<String, Object> params){
        return this.sdsQcFormShowService.getDataByAdm(params);
    }

    /**
     * @param params
     * @return
     * @Description: 获取病历溯源费用信息
     * @Title: getDataByFee
     * @author: zhangdc
     * @date: 2023年12月7日15:08:52
     */
    @RequestMapping(value = "/getDataByFee")
    @ResponseBody
    public Object getDataByFee(@RequestParam Map<String, Object> params){
        return this.sdsQcFormShowService.getDataByFee(params);
    }

    /**
     * @param params
     * @return
     * @Description: 获取病历溯源医嘱信息
     * @Title: getDataByOrder
     * @author: zhangdc
     * @date: 2023年12月7日15:08:52
     */
    @RequestMapping(value = "/getDataByOrder")
    @ResponseBody
    public Object getDataByOrder(@RequestParam Map<String, Object> params){
        return this.sdsQcFormShowService.getDataByOrder(params);
    }

    /**
     * @param params
     * @return
     * @Description: 获取病历溯源检验信息
     * @Title: getDataByLisReport
     * @author: zhangdc
     * @date: 2023年12月7日15:08:52
     */
    @RequestMapping(value = "/getDataByLisReport")
    @ResponseBody
    public Object getDataByLisReport(@RequestParam Map<String, Object> params){
        return this.sdsQcFormShowService.getDataByLisReport(params);
    }

    /**
     * @param params
     * @return
     * @Description: 获取病历溯源检验结果信息
     * @Title: getDataByLisResult
     * @author: zhangdc
     * @date: 2023年12月7日15:08:52
     */
    @RequestMapping(value = "/getDataByLisResult")
    @ResponseBody
    public Object getDataByLisResult(@RequestParam Map<String, Object> params){
        return this.sdsQcFormShowService.getDataByLisResult(params);
    }

    /**
     * @param params
     * @return
     * @Description: 获取病历溯源检查结果信息
     * @Title: getDataByRisReport
     * @author: zhangdc
     * @date: 2023年12月7日15:08:52
     */
    @RequestMapping(value = "/getDataByRisReport")
    @ResponseBody
    public Object getDataByRisReport(@RequestParam Map<String, Object> params){
        return this.sdsQcFormShowService.getDataByRisReport(params);
    }

    /**
     * @param params
     * @return
     * @Description: 获取病历溯源生命体征信息
     * @Title: getDataByNur
     * @author: zhangdc
     * @date: 2023年12月7日15:08:52
     */
    @RequestMapping(value = "/getDataByNur")
    @ResponseBody
    public Object getDataByNur(@RequestParam Map<String, Object> params){
        return this.sdsQcFormShowService.getDataByNur(params);
    }


    /**
     * @param params
     * @return 新病种信息
     * @Description: 退出当前病种后重新入组更低优先级的病种
     * @Title: reEnroll
     * @author: sunyj
     * @date: 2024年02月29日09:36:55
     */
    @RequestMapping(value = "/reEnroll")
    @ResponseBody
    public Object reEnroll(@RequestParam Map<String, Object> params) {
        return this.sdsQcFormShowService.reEnroll(params);
    }

}
